package com.bicon.botu.mall.base.rpc;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.bicon.botu.core.base.common.Constants;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.mall.base.common.ValidationUtil;
import com.bicon.botu.mall.base.entity.DeliveryPoint;
import com.bicon.botu.mall.base.entity.ExpressTemplate;
import com.fasterxml.jackson.databind.util.BeanUtil;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 发货点RPC
 *
 * @author liushujie
 * @date 2018/5/8 0008 下午 16:05
 */
@CrossOrigin
@RestController
@RequestMapping("/V3.0.0/rpc/delivery-point")
public class DeliveryPointRpc extends BaseController {

    /**
     * 获取发货点列表，按照默认发货排序
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public BaseResult enabled() {
        List<DeliveryPoint> deliveryPointList = new DeliveryPoint().selectList(new EntityWrapper<DeliveryPoint>().eq("logic_delete", Constants.DEL_LOGIC_NORMAL).orderBy("is_delivery", false).orderBy("create_date", false));
        return new BaseResult(Constants.RESPONSE_CODE_200, Constants.RESPONSE_MESSAGE_200, deliveryPointList);
    }

    /***
     * 获取收货列表，按照默认排序
     * @return
     */
    @RequestMapping(value = "/receive-list", method = RequestMethod.GET)
    public BaseResult list() {
        //根据默认收货 创建时间 排序
        List<DeliveryPoint> deliveryPointList = new DeliveryPoint().selectList(new EntityWrapper<DeliveryPoint>().eq("logic_delete", Constants.DEL_LOGIC_NORMAL).orderBy("is_receive", false).orderBy("create_date", false));
        return new BaseResult(Constants.RESPONSE_CODE_200, Constants.RESPONSE_MESSAGE_200, deliveryPointList);
    }

    @RequestMapping(value = "/point", method = RequestMethod.GET)
    public BaseResult<DeliveryPoint> queryById(@RequestParam String deliveryPointId) {
        //根据默认收货 创建时间 排序
        DeliveryPoint deliveryPoint = new DeliveryPoint().selectOne(new EntityWrapper<DeliveryPoint>().eq("logic_delete", Constants.DEL_LOGIC_NORMAL).eq("id",deliveryPointId));
        if(deliveryPoint!=null){
            return new BaseResult(Constants.RESPONSE_CODE_200, Constants.RESPONSE_MESSAGE_200, deliveryPoint);
        }
        return this.sendResult(Constants.RESPONSE_CODE_404,Constants.RESPONSE_MESSAGE_404);
    }
}
